﻿using System;
using System.Windows.Automation;

namespace QuickUIT.Controls
{
    /// <summary>
    /// Represents a split button control. 
    /// </summary>
    public class UISplitButton : UIBaseControl
    {
        /// <summary>
        /// Gets the expand collapse state of the split button. 
        /// </summary>
        public new ExpandCollapseState? ExpandCollapseState
        {
            get { return base.ExpandCollapseState; }
        }

        /// <summary>
        /// Gets whether the split button is expanded. 
        /// </summary>
        public bool IsExpanded
        {
            get
            {
                return (ExpandCollapseState.HasValue &&
                        ExpandCollapseState == System.Windows.Automation.ExpandCollapseState.Expanded);
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UISplitButton"/> class. 
        /// </summary>
        public UISplitButton()
            : base(ControlType.SplitButton)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UISplitButton"/> class.
        /// </summary>
        /// <param name="parent">The parent of this control.</param>
        public UISplitButton(UIBaseControl parent)
            : base(parent, ControlType.SplitButton)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UISplitButton"/> class.
        /// </summary>
        /// <param name="locator">The locator used to find the specific control.</param>
        public UISplitButton(string locator)
            : base(null, ControlType.SplitButton, locator)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UISplitButton"/> class.
        /// </summary>
        /// <param name="parent">The parent of this control.</param>
        /// <param name="locator">The locator used to find the specific control.</param>
        public UISplitButton(UIBaseControl parent, string locator)
            : base(parent, ControlType.SplitButton, locator)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UISplitButton"/> class.
        /// </summary>
        /// <param name="control">The underlying <see cref="AutomationElement"/> of the control.</param>
        public UISplitButton(AutomationElement control) : base(control, ControlType.SplitButton)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UISplitButton"/> class.
        /// </summary>
        /// <param name="parent">The parent of the control</param>
        /// <param name="control">The underlying <see cref="AutomationElement"/> of the control.</param>
        public UISplitButton(UIBaseControl parent, AutomationElement control) : base(parent, control, ControlType.SplitButton)
        {
        }

        /// <summary>
        /// Expands the split button, displaying all its child nodes, controls or content. 
        /// </summary>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public new void Expand()
        {
            base.Expand();
        }

        /// <summary>
        /// Collapses the split button, hiding all its child nodes, controls or content. 
        /// </summary>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public new void Collapse()
        {
            base.Collapse();
        }

        /// <summary>
        /// Presses the split button. 
        /// </summary>
        public void Press()
        {
            Invoke();
        }
    }
}
